package com.bd.module.login.ui;
import java.awt.Font;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.Map;

import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JTextField;

import com.bd.framework.pojo.IniInfo;
import com.bd.framework.utils.IniConfig;

public class IniReader {
	/**JLabel标签的字体样式*/
	private final Font LID_FONT = new Font("楷体", Font.PLAIN, 20);
	/**按钮字体*/
	private final Font BTN_FONT = new Font("楷体", Font.PLAIN, 20);
	private IniConfig iniConfig = new IniConfig();
	private IniInfo iniInfo = null;

	private JFrame jFrame = new JFrame("读取配置示例");

	private JLabel jLabel1 = new JLabel("主服务器IP地址");
	private JTextField jTextField1 = new JTextField(40);

	private JLabel jLabel2 = new JLabel("备服务器IP地址");
	private JTextField jTextField2 = new JTextField(30);

	private JLabel jLabel3 = new JLabel("门店");
	private JTextField jTextField3 = new JTextField(30);

	private JLabel jLabel4 = new JLabel("门店服务器id");
	private JTextField jTextField4 = new JTextField(30);

	private JLabel jLabel5 = new JLabel("是否允许组合");
	private JTextField jTextField5 = new JTextField(30);

	private JLabel jLabel6 = new JLabel("最近下载时间");
	private JTextField jTextField6 = new JTextField(30);

	private JLabel jLabel7 = new JLabel("下载次数");
	private JTextField jTextField7 = new JTextField(30);

	private JLabel jLabel8 = new JLabel("在线/离线");
	private JTextField jTextField8 = new JTextField(30);

	private JLabel jLabel9 = new JLabel("退货方式");
	private JTextField jTextField9 = new JTextField(30);

	private JLabel jLabel10 = new JLabel("礼券收款后方式");
	private JTextField jTextField10 = new JTextField(30);

	private JLabel jLabel11 = new JLabel("小票的抬头");
	private JTextField jTextField11 = new JTextField(30);

	private JLabel jLabel12 = new JLabel("打印机类型");
	private JTextField jTextField12 = new JTextField(30);

	private JButton jButton1 = new JButton("取消");

	private JButton jButton2 = new JButton("确定");

	void showFrame() {
		Map<String, Object> map = iniConfig.getIniInfo();
		if (map.get("error") == null || map.get("error").equals(null)) {
			iniInfo = (IniInfo) map.get("success");
		} else {
			JOptionPane.showMessageDialog(null, map.get("error"));
			return;
		}
		jTextField1.setText(iniInfo.getMainIp());
		jTextField2.setText(iniInfo.getBackupIp());
		jTextField3.setText(iniInfo.getShopCode());
		jTextField4.setText(iniInfo.getServerId());
		jTextField5.setText(iniInfo.getDynamic());
		jTextField6.setText(iniInfo.getDownTime());
		jTextField7.setText(iniInfo.getDownTimes());
		jTextField8.setText(iniInfo.getOffLine());
		jTextField9.setText(iniInfo.getPoint());
		jTextField10.setText(iniInfo.getBhFlag());
		jTextField11.setText(iniInfo.getCkFlag());
		jTextField12.setText(iniInfo.getBillNum());

		jButton1.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				jTextField1.setText(iniInfo.getMainIp());
				jTextField2.setText(iniInfo.getBackupIp());
				jTextField3.setText(iniInfo.getShopCode());
				jTextField4.setText(iniInfo.getServerId());
				jTextField5.setText(iniInfo.getDynamic());
				jTextField6.setText(iniInfo.getDownTime());
				jTextField7.setText(iniInfo.getDownTimes());
				jTextField8.setText(iniInfo.getOffLine());
				jTextField9.setText(iniInfo.getPoint());
				jTextField10.setText(iniInfo.getBhFlag());
				jTextField11.setText(iniInfo.getCkFlag());
				jTextField12.setText(iniInfo.getBillNum());
			}
		});

		jButton2.addActionListener(new ActionListener() {

			public void actionPerformed(ActionEvent e) {
				IniInfo ini = new IniInfo();
				ini.setMainIp(jTextField1.getText());
				ini.setBackupIp(jTextField2.getText());
				ini.setShopCode(jTextField3.getText());
				ini.setServerId(jTextField4.getText());
				ini.setDynamic(jTextField5.getText());
				ini.setDownTime(jTextField6.getText());
				ini.setDownTimes(jTextField7.getText());
				ini.setOffLine(jTextField8.getText());
				ini.setPoint(jTextField9.getText());
				ini.setBhFlag(jTextField10.getText());
				ini.setCkFlag(jTextField11.getText());
				ini.setBillNum(jTextField12.getText());
				String strFlag = iniConfig.saveIniInfo(ini);
				JOptionPane.showMessageDialog(jFrame, strFlag);
			}
		});

		jLabel1.setBounds(32, 10, 147, 30);
		jLabel1.setFont(LID_FONT);
		jTextField1.setBounds(189, 10, 139, 30);
		jLabel2.setBounds(338, 10, 150, 30);
		jLabel2.setFont(LID_FONT);
		jTextField2.setBounds(508, 10, 140, 30);

		jLabel3.setBounds(32, 44, 147, 30);
		jLabel3.setFont(LID_FONT);
		jTextField3.setBounds(189, 44, 139, 30);
		jLabel4.setBounds(338, 44, 150, 30);
		jLabel4.setFont(LID_FONT);
		jTextField4.setBounds(508, 44, 140, 30);

		jLabel5.setBounds(32, 79, 147, 30);
		jLabel5.setFont(LID_FONT);
		jTextField5.setBounds(189, 79, 139, 30);
		jLabel6.setBounds(338, 79, 150, 30);
		jLabel6.setFont(LID_FONT);
		jTextField6.setBounds(508, 79, 140, 30);

		jLabel7.setBounds(32, 116, 147, 30);
		jLabel7.setFont(LID_FONT);
		jTextField7.setBounds(189, 116, 139, 30);
		jLabel8.setBounds(338, 116, 150, 30);
		jLabel8.setFont(LID_FONT);
		jTextField8.setBounds(508, 116, 140, 30);
		jLabel9.setBounds(32, 150, 147, 30);
		jLabel9.setFont(LID_FONT);
		jTextField9.setBounds(189, 150, 139, 30);
		jLabel10.setBounds(338, 150, 150, 30);
		jLabel10.setFont(LID_FONT);
		jTextField10.setBounds(508, 150, 140, 30);
		jLabel11.setBounds(32, 190, 147, 30);
		jLabel11.setFont(LID_FONT);
		jTextField11.setBounds(189, 190, 139, 30);
		jLabel12.setBounds(338, 190, 150, 30);
		jLabel12.setFont(LID_FONT);
		jTextField12.setBounds(508, 190, 140, 30);

		jFrame.getContentPane().setLayout(null);
		jFrame.getContentPane().setFont(new Font("楷体", Font.PLAIN, 20));
		jFrame.setTitle("更新pos机配置");
		jFrame.setFont(BTN_FONT);
		jFrame.getContentPane().add(jLabel1);
		jFrame.getContentPane().add(jLabel2);
		jFrame.getContentPane().add(jLabel3);
		jFrame.getContentPane().add(jLabel4);
		jFrame.getContentPane().add(jLabel5);
		jFrame.getContentPane().add(jLabel6);
		jFrame.getContentPane().add(jLabel7);
		jFrame.getContentPane().add(jLabel8);
		jFrame.getContentPane().add(jLabel9);
		jFrame.getContentPane().add(jLabel10);
		jFrame.getContentPane().add(jLabel11);
		jFrame.getContentPane().add(jLabel12);

		jFrame.getContentPane().add(jTextField1);
		jFrame.getContentPane().add(jTextField2);
		jFrame.getContentPane().add(jTextField3);
		jFrame.getContentPane().add(jTextField4);
		jFrame.getContentPane().add(jTextField5);
		jFrame.getContentPane().add(jTextField6);
		jFrame.getContentPane().add(jTextField7);
		jFrame.getContentPane().add(jTextField8);
		jFrame.getContentPane().add(jTextField9);
		jFrame.getContentPane().add(jTextField10);
		jFrame.getContentPane().add(jTextField11);
		jFrame.getContentPane().add(jTextField12);

		jButton1.setBounds(137, 242, 89, 30);
		jButton1.setFont(BTN_FONT);
		jButton2.setBounds(428, 242, 89, 30);
		jButton2.setFont(BTN_FONT);
		
		jFrame.getContentPane().add(jButton1);
		jFrame.getContentPane().add(jButton2);

		jFrame.setBounds(370, 200, 699, 328);
		jFrame.setVisible(true);

	}

	public static void main(String[] args) {
		new IniReader().showFrame();
	}

}
